<?php
// created 6/13/12
// unneeded session_start();

class Query_models extends CI_Model{
    
    public function how_many_controlled_characters() {
        
        $user_id = $_SESSION["user"];
        
        $query = $this->doctrine->em->createQuery("SELECT u 
                FROM ORM\Dynasties2\Characters u 
                WHERE u.playerControlled = $user_id
                ");
        
        return $query->getResult();
        
        
    }  // end of function how_many_controlled_characters ///////////////////////////
    //////////////////////////////////////////////////////////////////
    
    public function my_titles() {
        
        $character = $_SESSION["active_character"];
        
        $query = $this->doctrine->em->createQuery("SELECT u 
                FROM ORM\Dynasties2\Titles u 
                WHERE u.characterLink = $character
                ");
        
        return $query->getResult();
        
        
    }  // end of function my_titles ///////////////////////////
    //////////////////////////////////////////////////////////////////
    
    public function my_wars() {
        
        $character = $_SESSION["active_character"];
        
        $query = $this->doctrine->em->createQuery("SELECT u 
                FROM ORM\Dynasties2\Wars u 
                WHERE u.attacker = $character
                    OR u.defender = $character
                ");
        
        return $query->getResult();
        
        
    }  // end of function my_titles ///////////////////////////
    //////////////////////////////////////////////////////////////////
    
    public function my_army() {
        
        $character = $_SESSION["active_character"];
        
        $query = $this->doctrine->em->createQuery("SELECT u 
                FROM ORM\Dynasties2\Armies u 
                WHERE u.controlledBy = $character
                ");
        
        return $query->getResult();
        
        
    }  // end of function my_army ///////////////////////////
    //////////////////////////////////////////////////////////////////
    
    public function my_army_forces($army) {
        
        $character = $_SESSION["active_character"];
        
        $query = $this->doctrine->em->createQuery("SELECT u 
                FROM ORM\Dynasties2\Armyforces u 
                WHERE u.armyLink = $army
                ");
        
        return $query->getResult();
        
        
    }  // end of function my_army_forces ///////////////////////////
    //////////////////////////////////////////////////////////////////
    
    
    public function get_adjacent_titles() {
        
        $character = $_SESSION["active_character"];
        
        $query = $this->doctrine->em->createQuery("SELECT u 
                FROM ORM\Dynasties2\Armyforces u 
                WHERE u.armyLink = '2594'
                ");
        
        return $query->getResult();
        
        
    }  // end of function my_army_forces ///////////////////////////
    //////////////////////////////////////////////////////////////////
    
    
}